package cn.com.project.pattern.d.multition;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Desc 多例模式，懒汉模式，用到才创建对象，资源最优
 */
public class Multition {
	
	private static final int COUNT = 2;
	
	private static final Random RANDOM = new Random();

	private Multition() {}
	
	private static final class MultitionInstance {
		private static final List<Multition> MultitionList = new ArrayList<Multition>(COUNT);
		static {
			for (int i = 0; i < COUNT; i++) {
				MultitionList.add(new Multition());
			}
		}
	}
	
	public static Multition getInstanceList() {
		return MultitionInstance.MultitionList.get(RANDOM.nextInt(COUNT));
	}
}

